#include <iostream>
#include <iomanip>
#include "EquationSolver.h"

using namespace std;

//D题各函数
double func1(double x)
{
        return sin(x/2) - 1;
}

double func2(double x)
{
        return exp(x) - tan(x);
}

double func3(double x)
{
        return x*x*x - 12*x*x + 3*x + 1 ;
}

int main()
{
    typedef double (*fp)(double);
    fp fpi[] = {func1, func2, func3};
    MyFunc f1(fpi[0]);
    MyFunc f2(fpi[1]);
    MyFunc f3(fpi[2]);

    double err = std::numeric_limits<double>::epsilon();
    Secant S1(0,M_PI/2,err,err,100,f1);
    Secant S2(1,1.4,err,err,100,f2);
    Secant S3(0,-0.5,err,err,100,f3);

    cout << "Question D: " << endl;
    cout << "The secant result of f1 is " << setiosflags(ios::fixed) << setprecision(2) << S1.solve() << endl;
    cout << "The secant result of f2 is " << setiosflags(ios::fixed) << setprecision(2) << S2.solve() << endl;
    cout << "The secant result of f3 is " << setiosflags(ios::fixed) << setprecision(2) << S3.solve() << endl;
    cout << "In S3, we change x0=3 x1=2 " << endl;
    Secant S3plus(3,2,err,err,100,f3);
    cout << "The secant result of f3plus is " << setiosflags(ios::fixed) << setprecision(2) << S3plus.solve() << endl;
    cout << "Because there are different solutions in one equation." << endl;
    cout << endl;

    return 0;
}